package com.wzt.lianfirecontrol.adapter.yuyueweibao;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.adapter.BaseRecyclerAdapter;
import com.wzt.lianfirecontrol.bean.recode.function.yuyueweibao.YuYueEvaluateModel;
import com.wzt.lianfirecontrol.utils.Utils;

public class YuYueEvaluateAdapter extends BaseRecyclerAdapter<YuYueEvaluateModel> {

    private Context context;

    public YuYueEvaluateAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_yuyue_evaluate_list, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, YuYueEvaluateModel data) {
        setMyData((MyViewHolder)viewHolder, data, RealPosition);
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private LinearLayout ll_item_content;
        private ImageView iv_star_1;
        private ImageView iv_star_2;
        private ImageView iv_star_3;
        private ImageView iv_star_4;
        private ImageView iv_star_5;
        private TextView tv_remark;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initMyView(this, itemView);
        }
    }

    private void initMyView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.ll_item_content = itemView.findViewById(R.id.ll_item_content);
        myViewHolder.iv_star_1 = itemView.findViewById(R.id.iv_star_1);
        myViewHolder.iv_star_2 = itemView.findViewById(R.id.iv_star_2);
        myViewHolder.iv_star_3 = itemView.findViewById(R.id.iv_star_3);
        myViewHolder.iv_star_4 = itemView.findViewById(R.id.iv_star_4);
        myViewHolder.iv_star_5 = itemView.findViewById(R.id.iv_star_5);
        myViewHolder.tv_remark = itemView.findViewById(R.id.tv_remark);
    }

    private void setMyData(MyViewHolder viewHolder, YuYueEvaluateModel data, int position) {
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setColor(context.getResources().getColor(R.color.white));
        if (position == 0){
            viewHolder.ll_item_content.setPadding(Utils.dip2px(context, 15), 0,
                    Utils.dip2px(context, 15), Utils.dip2px(context, 15));
        }else {
            viewHolder.ll_item_content.setPadding(Utils.dip2px(context, 15), Utils.dip2px(context, 15),
                    Utils.dip2px(context, 15),Utils.dip2px(context, 15));
        }
        if (position == getmDatas().size() - 1){
            gradientDrawable.setCornerRadii(new float[]{ 0, 0, 0, 0, Utils.dip2px(context, 6), Utils.dip2px(context, 6),
                    Utils.dip2px(context, 6), Utils.dip2px(context, 6)});
        }else {
            gradientDrawable.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
        }
        viewHolder.ll_item_content.setBackground(gradientDrawable);
        viewHolder.iv_star_1.setImageResource(R.mipmap.icon_star_bad);
        viewHolder.iv_star_2.setImageResource(R.mipmap.icon_star_bad);
        viewHolder.iv_star_3.setImageResource(R.mipmap.icon_star_bad);
        viewHolder.iv_star_4.setImageResource(R.mipmap.icon_star_bad);
        viewHolder.iv_star_5.setImageResource(R.mipmap.icon_star_bad);
        switch (data.getStar()){
            case "5":
                viewHolder.iv_star_5.setImageResource(R.mipmap.icon_star_good);
            case "4":
                viewHolder.iv_star_4.setImageResource(R.mipmap.icon_star_good);
            case "3":
                viewHolder.iv_star_3.setImageResource(R.mipmap.icon_star_good);
            case "2":
                viewHolder.iv_star_2.setImageResource(R.mipmap.icon_star_good);
            case "1":
                viewHolder.iv_star_1.setImageResource(R.mipmap.icon_star_good);
        }
        viewHolder.tv_remark.setText(data.getRemark());
    }
}
